﻿using cfg.Myskill;
using UnityEngine;

public class PlayerCloneController: CloneController
{
    [SerializeField]private Transform attackPos;
    
    private bool canHitBack = true;//默认开启击退
    public void PlayAttack()
    {
        var attackNum = Random.Range(1, 3);
        animator.SetInteger("AttackNum", attackNum);
    }

    public void SetCanHitBack(bool canHitBack)
    {
        this.canHitBack = canHitBack;
    }

    public void TriggerAttack()
    {
        Collider2D[] collider2Ds = Physics2D.OverlapCircleAll(attackPos.position,
            Setting.attackRadius,LayerMask.NameToLayer("Enmey"));
        
        foreach (Collider2D item in collider2Ds)
        {
            EnemyStateController enemyStateController = item.GetComponent<EnemyStateController>();
            if (enemyStateController != null)
            {
                var damgeInfo = new DamgeInfo()
                {
                    attacker = controller.characterBase,
                    targeter = enemyStateController.characterBase,
                    damage = controller.GetDamage()+skillInfo.SkillDamage,
                };
                if (canHitBack)
                {
                    damgeInfo.hitBackForce = new Vector2(faceDir* 5, 5);
                    damgeInfo.hitBackTime = 0.2f;
                }
                enemyStateController.Damage(damgeInfo);
            }
        }
    }
}